<template>
    <div class="edu-page-warp">
        <div class="tab" v-if="this.tabs.length > 0">
            <div v-for="(t,index) in tabs">
                <span :class="tabFocus==t.val?'current':''" @click="changeTab(t.val)">{{t.text}}</span>
                <span v-if="index!=tabs.length-1" class="split">|</span>
            </div>
        </div>
        <div style="clear:both"></div>
        <!--国家专业学位目录查询-->
        <div v-if="tabFocus==0">
          <condition-card :labelWidth="'140px'" @reset="reset" @search="onSubmit">
			      <el-row>
              <el-col :span="8">
                <el-form-item :label="$t('professions.professionalDegreeCateGory')">
                   <!--  <el-form-item :label="$t('professions.professionalDegreeInfo')"> -->
                  <el-select v-model="queryForm.levelTwoIdList" multiple collapse-tags clearable filterable>
                    <el-option
                      v-for="item in options.categories"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </condition-card>
            <el-card shadow="never">
                <div class="edu-page-title" style="margin-bottom:16px">{{$t('professions.nationalProfessionalDegreeCatalogueQuery')}}</div>
                <div class="edu-opertion-bar"  style="margin-bottom:16px">
                    <div class="float-left">
                        <el-input
                            v-model="queryForm.condition"
                            :placeholder="$t('professions.plsInputProfessionalDomain')"
                            style="width:260px"
                            @keyup.enter.native="onSubmit"
                        >
                            <i
                                class="el-icon-search"
                                slot="suffix"
                                style="margin-top:10px;cursor:pointer"
                                @click="onSubmit"
                            ></i>
                        </el-input>
                    </div>
                    <div class="float-right">
                        <el-button type="primary" @click="handleExport">{{$t("message.export")}}</el-button>
                        <!-- <el-button  @click="test">测试</el-button> -->
                    </div>
                </div>
                <el-table stripe :data="viewData" size="mini" width="100%" :key="Math.random()" tooltip-effect="light">
                    <edu-table-column :label="$t('professions.professionalCategroyCode')" :render-header="labelHead" prop="levelTwoCode" />
                    <edu-table-column :label="$t('professions.professionalCategroyName')" :render-header="labelHead" prop="levelTwoName" />
                    <edu-table-column :label="$t('professions.professionalCategroyNameEn')" :render-header="labelHead" prop="levelTwoNameEn" />
                    <edu-table-column :label="$t('professions.professionalDomainCode')" :render-header="labelHead" prop="code" />
                    <edu-table-column :label="$t('professions.professionalDomainName')" :render-header="labelHead" prop="name" />
                    <edu-table-column :label="$t('professions.professionalDomainNameEn')" :render-header="labelHead" prop="nameEn" />
                </el-table>
                <el-row>
                    <el-col>
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="queryForm.pageNum_"
                            :page-sizes="[20,50,100,500,1000]"
                            :page-size="queryForm.pageSize_"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="queryForm.total_"
                            style="float:right;margin-top:10px"
                        ></el-pagination>
                    </el-col>
                </el-row>
            </el-card>
        </div>
        <!--国家专业学位类别维护-->
        <div v-if="tabFocus==1">
            <el-card shadow="never">
                 <div style="margin-bottom: 16px;font-size: 16px;">{{$t('professions.nationalProfessionalDegreeCategoryMaintenance')}}</div>
                <div class="edu-opertion-bar" style="margin-bottom:16px">
                    <div class="float-left">
                        <el-input
                            v-model="queryForm.condition"
                            :placeholder="$t('professions.plsInputProfessionalDegree')"
                            style="width:260px" clearable
                            @keyup.enter.native="onSubmit"
                        >
                            <i
                                class="el-icon-search"
                                slot="suffix"
                                style="margin-top:10px;cursor:pointer"
                                @click="onSubmit"
                            ></i>
                        </el-input>
                    </div>
                    <div class="float-right">
                        <el-dropdown @command="importDegreeRecord">
                            <el-button>
                                {{$t('message.import')}}
                                <i class="el-icon-arrow-down el-icon--right"></i>
                            </el-button>
                            <el-dropdown-menu :disabled="importButton" slot="dropdown">
                                <el-dropdown-item command="in">{{$t('message.import')}}</el-dropdown-item>
                                <el-dropdown-item command="out">{{$t('message.down')}}</el-dropdown-item>
                            </el-dropdown-menu>
					    </el-dropdown>
                       <!--  <el-button @click="downDegreeFiles">{{$t('message.down')}}</el-button>
                        <el-button @click="importDegreeFiles">{{$t("message.import")}}</el-button> -->
                        <el-button type="primary" @click="create">{{$t("message.add")}}</el-button>
                    </div>
                </div>
                <el-table stripe :data="viewData" size="mini" width="100%" :key="Math.random()" tooltip-effect="light">
                    <edu-table-column :render-header="labelHead" :label="$t('professions.professionalCategroyCode')" prop="code" />
                    <edu-table-column :render-header="labelHead" :label="$t('professions.professionalCategroyName')" prop="name" />
                    <edu-table-column :render-header="labelHead" :label="$t('professions.professionalCategroyNameEn')" prop="nameEn" />
                    <edu-table-column  :label="$t('message.operating')">
                        <template slot-scope="props">
                            <el-button
                                type="text"
                                size="mini"
                                @click="commonEdit(props.row)"
                            >{{$t("message.edit")}}</el-button>
                            <el-button
                                type="text"
                                size="mini"
                                @click="commonDelete(props.row)"
                            >{{$t("message.delete")}}</el-button>
                        </template>
                    </edu-table-column>
                </el-table>
                <el-row>
                    <el-col>
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="queryForm.pageNum_"
                            :page-sizes="[20,50,100,500,1000]"
                            :page-size="queryForm.pageSize_"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="queryForm.total_"
                            style="float:right;margin-top:10px"
                        ></el-pagination>
                    </el-col>
                </el-row>
            </el-card>
        </div>
        <!--国家专业领域维护-->
        <div v-if="tabFocus==2">
          <condition-card :labelWidth="'110px'"  @reset="reset" @search="onSubmit">
			       <el-row>
               <el-col :span="8">
                <el-form-item :label="$t('professions.professionalDegreeCateGory')">
                    <el-select v-model="queryForm.parentIdList" multiple collapse-tags clearable filterable>
                        <el-option
                            v-for="item in options.categories"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </el-form-item>
               </el-col>
               <el-col :span="8">
                 <el-form-item :label="$t('professions.isValid')">
                   <el-select v-model="queryForm.status" clearable>
                     <el-option
                       v-for="item in options.valids"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value"
                     ></el-option>
                   </el-select>
                 </el-form-item>
               </el-col>
			     </el-row>
          </condition-card>

            <el-card shadow="never">
                <div style="margin-bottom: 16px;font-size: 16px;">{{$t('professions.nationalProfessionalDomainMaintenance')}}</div>
                <div class="edu-opertion-bar" style="margin-bottom:16px">
                    <div class="float-left">
                        <el-input
                            v-model="queryForm.condition"
                            :placeholder="$t('professions.plsInputProfessionalDomain')"
                            style="width:260px"
                            @keyup.enter.native="onSubmit"
                        >
                            <i
                                class="el-icon-search"
                                slot="suffix"
                                style="margin-top:10px;cursor:pointer"
                                @click="onSubmit"
                            ></i>
                        </el-input>
                    </div>
                    <div class="float-right">
                        <el-dropdown @command="importDomainRecord">
                            <el-button>
                                {{$t('message.import')}}
                                <i class="el-icon-arrow-down el-icon--right"></i>
                            </el-button>
                            <el-dropdown-menu :disabled="importButton" slot="dropdown">
                                <el-dropdown-item command="in">{{$t('message.import')}}</el-dropdown-item>
                                <el-dropdown-item command="out">{{$t('message.down')}}</el-dropdown-item>
                            </el-dropdown-menu>
					    </el-dropdown>
                       <!--  <el-button @click="downDomainFiles">{{$t('message.down')}}</el-button>
                        <el-button @click="importDomainFiles">{{$t("message.import")}}</el-button> -->
                        <el-button type="primary" @click="create">{{$t("message.add")}}</el-button>
                    </div>
                </div>
                <el-table stripe :data="viewData" size="mini" width="100%" :key="Math.random()" tooltip-effect="light">
                  <edu-table-column :render-header="labelHead" :label="$t('professions.professionalCategroyCode')" prop="parentCode" />
                  <edu-table-column :render-header="labelHead" :label="$t('professions.professionalCategroyName')" prop="parentName" />
                  <edu-table-column :render-header="labelHead" :label="$t('professions.professionalDomainCode')" prop="code" />
                  <edu-table-column :render-header="labelHead" :label="$t('professions.professionalDomainName')" prop="name" />
                  <edu-table-column :render-header="labelHead" :label="$t('professions.professionalDomainNameEn')" prop="nameEn" />
                  <edu-table-column :label="$t('message.operating')">
                      <template slot-scope="props">
                          <el-button
                              type="text"
                              size="mini"
                              @click="commonEdit(props.row)"
                          >{{$t("message.edit")}}</el-button>
                          <el-button
                              type="text"
                              size="mini"
                              @click="commonDelete(props.row)"
                          >{{$t("message.delete")}}</el-button>
                      </template>
                  </edu-table-column>
                </el-table>
                <el-row>
                    <el-col>
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="queryForm.pageNum_"
                            :page-sizes="[20,50,100,500,1000]"
                            :page-size="queryForm.pageSize_"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="queryForm.total_"
                            style="float:right;margin-top:10px"
                        ></el-pagination>
                    </el-col>
                </el-row>
            </el-card>
        </div>
        <!--国家专业学位类别维护对话框-->
        <el-dialog
            :title="dialogTitle"
            width="500px"
            :visible.sync="showCategoryDialog"
            @close="resetFormValidate()"
            :close-on-click-modal="false"
            v-drag-dialog
        >
            <el-form
                :model="postForm"
                label-position="right"
                label-width="170px"
                :rules="rules"
                ref="postForm1"
                label-suffix="："
            >
                <el-row>
                    <el-col :offset="3" :span="18">
                        <el-form-item :label="$t('professions.professionalCategroyCode')" prop="code">
                            <el-input  :placeholder="$t('common.pla.pleaseInput')"  v-model="postForm.code" maxlength="32"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :offset="3" :span="18">
                        <el-form-item :label="$t('professions.professionalCategroyName')" prop="name">
                            <el-input  :placeholder="$t('common.pla.pleaseInput')"  v-model="postForm.name" maxlength="50"/>
                        </el-form-item>
                    </el-col>
               </el-row>
                <el-row>
                    <el-col :offset="3" :span="18">
                        <el-form-item  :label="$t('professions.professionalCategroyNameEn')" prop="nameEn">
                            <el-input :placeholder="$t('common.pla.pleaseInput')"  v-model="postForm.nameEn" maxlength="50"/>
                        </el-form-item>
                    </el-col>
               </el-row>
                <el-row>
                    <el-col :offset="3" :span="18">
                        <el-form-item :label="$t('message.remark')"  prop="remark">
                            <el-input
                               :placeholder="$t('common.pla.pleaseInput')"
                                type="textarea"
                                rows="4"
                                v-model="postForm.remark"
                                maxlength="255"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <div class="float-right">
                            <el-button @click="cancel">{{$t("message.cancel")}}</el-button>
                            <el-button type="primary" @click="commonSave">{{$t("message.save")}}</el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>
        <!--国家专业领域维护对话框-->
        <el-dialog
            :title="dialogTitle"
            width="500px"
            :visible.sync="showFirstLevelDialog"
            @close="resetFormValidate()"
            :close-on-click-modal="false"
            v-drag-dialog
        >
            <el-form
                :model="postForm"
                label-position="right"
                label-width="170px"
                :rules="rules"
                ref="postForm2"
                label-suffix="："
            >
                <el-row>
                    <el-col :offset="3" :span="18">
                        <el-form-item :label="$t('professions.professionalDegreeCateGory')" prop="parentId">
                            <el-select :placeholder="$t('common.pla.pleaseSelect')" v-model="postForm.parentId" style="width: 100%;">
                                <el-option
                                    v-for="item in options.categories"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :offset="3" :span="18">
                        <el-form-item :label="$t('professions.professionalDomainCode')" prop="code">
                            <el-input :placeholder="$t('common.pla.pleaseInput')"  v-model="postForm.code" maxlength="32"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :offset="3" :span="18">
                        <el-form-item :label="$t('professions.professionalDomainName')"  prop="name">
                            <el-input :placeholder="$t('common.pla.pleaseInput')"  v-model="postForm.name" maxlength="50"/>
                        </el-form-item>
                    </el-col>
                    </el-row>
                <el-row>
                    <el-col :offset="3" :span="18">
                        <el-form-item :label="$t('professions.professionalDomainNameEn')" prop="nameEn">
                            <el-input :placeholder="$t('common.pla.pleaseInput')"  v-model="postForm.nameEn" maxlength="50"/>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                  <el-col :offset="3" :span="18">
                    <el-form-item :label="$t('professions.isValid')" prop="status">
                      <el-select v-model="postForm.status" clearable style="width: 100%;">
                        <el-option v-for="item in options.valids" :key="item.value" :label="item.label" :value="item.value"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                    <el-col :offset="3" :span="18">
                        <el-form-item :label="$t('message.remark')" prop="remark">
                            <el-input
                               :placeholder="$t('common.pla.pleaseInput')"
                                type="textarea"
                                rows="4"
                                v-model="postForm.remark"
                                maxlength="255"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <div class="float-right">
                            <el-button @click="cancel">{{$t("message.cancel")}}</el-button>
                            <el-button type="primary" @click="commonSave">{{$t("message.save")}}</el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>

         <EduAsyncUpload ref="uploadDia" :data="queryParams" :action="importUrl" />

           <!-- 导入页面 -->
                <edu-dialog
                    :title="uploadTittle"
                    width="500px"
                    ref="uploadDialog"
                    @close="clearFiles"
                    @confirm="uploadFile"
                >
                <el-form label-width="85px">
                    <el-row>
                         <el-form-item>
                            <el-upload
                                ref="upload"
                                :data="{}"
                                :on-success="uploadDone"
                                :before-upload="beforeAvatarUpload"
							    :before-remove="beforeRemove"
                                :on-error="onError"
                                :auto-upload="false"
                                :multiple="false"
                                :on-change="(file, fileList)=>{this.fileList = fileList}"
                                :limit="1"
                                :accept="'application/vnd.ms-excel'"
                                :action="importUrl"
                            >
                                    <el-button slot="trigger" size="small" type="primary">{{$t('label.selectFile')}}</el-button>
                                    <div slot="tip" class="el-upload__tip">{{$t('culture.profession.uploadXLSFileOnly')}}</div>
                            </el-upload>
                        </el-form-item>
                    </el-row>
                </el-form>
            </edu-dialog>

             <!-- 导入提示对话框 -->
            <edu-export-dialog :tip="$t('common.upload.professionDegreeMajor')" @close="closeFresh" ref="importRef" :data="importCam">
                <div :style="fontStyle">{{msg}}</div>
               <div style="margin-top: 4px;font-size: 12px;color: #909399">{{errorInfo1}}</div>
                <div style="margin-top: 4px;font-size: 12px;color: #909399">{{errorInfo2}}</div>
            </edu-export-dialog>
    </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import {
    addMajor,
    getMajorList,
    getMajorById,
    editMajor,
    deleteMajor,
    getAllMajorList,
    exportMajor,
    getReportStatus,
    downloadDegreeUrl,
    downloadDomainUrl,
    getimportStatus
} from "common/src/api/resource/course";
import mixin from 'common/src/mixins/index';
export default {
    name: "professionDegreeMajor",
    mixins: [mixin],
    data() {
        return {
            dialogTitle:'',
            msg:'',
            errorInfo1: '',
            errorInfo2: '',
            importCam:null,
            importButton: false,
            fontStyle: 'font-size: 15px;color: #606266;',
            type: 2,
            tabs: [
                {
                    text: this.$t('professions.nationalProfessionalDegreeCatalogueQuery'),
                    val: 0
                },
                {
                    text: this.$t('professions.nationalProfessionalDegreeCategoryMaintenance'),
                    val: 1
                },
                {
                    text: this.$t('professions.nationalProfessionalDomainMaintenance'),
                    val: 2
                }
            ],
            queryForm: {
                level: null,
                condition: "",
                levelOneId: null,
                levelTwoId: null,
                levelTwoIdList: [],
                parentId: null,
                parentIdList:[],
                status:null,
                pageNum_: 1,
                pageSize_: 20,
                total_: 0
            },
            postForm: {
                code: "",
                name: "",
                nameEn: "",
                parentId: "",
                level: "",
                status:"",
                remark: "",
                remarkEn: ""
            },
            options: {
                categories: [],
                valids:[
                    { label: this.$t("message.yes"), value: 1 },
                    { label: this.$t("message.no"), value: 0 }
                ]
            },
            rules: {
                code: [
                    {
                        required: true,
                        message: this.$t('professions.plsInputCode'),
                        trigger: "blur"
                    }
                ],
                name: [
                    {
                        required: true,
                        message: this.$t('professions.plsInputName'),
                        trigger: "blur"
                    }
                ],
                nameEn: [
                    {
                        required: true,
                        message: this.$t('professions.plsInputNameEn'),
                        trigger: "blur"
                    }
                ],
                status: [
                    {
                        required: true,
                        message: this.$t('professions.plsChooseValidStatus'),
                        trigger: "blur"
                    }
                ],
                parentId: [
                    {
                        required: true,
                        message: this.$t('professions.plsInputPrarent'),
                        trigger: "blur"
                    }
                ]
            },
            tabFocus: 0,
            viewData: [],
            showCategoryDialog: false,
            showFirstLevelDialog: false,
            editId: "",
            importUrl: '',
            uploadTittle: ""
        };
    },
    mounted: function() {
        this.init();
    },
    methods: {
        init() {
            this.queryForm.level = 2;
            this.queryForm.type = this.type;
            this.queryForm.page = false;
            this.postForm.type = this.type;
            this.getTabs();
            this.getCategories();
            this.onSubmit();
        },
        onSubmit() {
           if (this.tabFocus) {
              this.queryForm.level = this.tabFocus;
            } else {
              this.queryForm.level = 2;
           }
           this.getDataList();
        },
        reset() {
            this.queryForm.condition = "";
            this.queryForm.levelOneId = null;
            this.queryForm.levelTwoId = null;
            this.queryForm.levelTwoIdList = [];
            this.queryForm.parentId = null;
            this.queryForm.parentIdList = [];
            this.queryForm.status = null;//是否生效
            this.onSubmit();
        },
        getDataList(isFirstPage = true) {
            if (isFirstPage) {
                this.queryForm.pageNum_ = 1;
            }
            getMajorList(this.queryForm).then(res => {
                if (res.code == 200) {
                    this.viewData = res.data.list;
                    this.queryForm.total_ = res.data.total_;
                }
            });
        },
        handleSizeChange(val) {
            this.queryForm.pageSize_ = val;
            this.getDataList();
        },
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val;
            this.getDataList(false);
        },
        //切换Tab
        changeTab(val) {
            this.reset();
            this.tabFocus = val;
            this.queryForm.page = val == 0 ? false : null;
            this.getCategories();
            this.onSubmit();
        },
        getTabs(){
            if(!this.global.isAdmin){
                this.tabs = [];
                this.tabFocus = 0;
            }
        },
        getCategories() {
            let data = {
                level: 1,
                type: this.type,
                page: false
            };
            getAllMajorList(data).then(res => {
                if (res.code == 200) {
                    this.options.categories = res.data.list.map(c => {
                        return {
                            label: c.name,
                            value: c.id
                        };
                    });
                }
            });
        },
        //新建门类
        create() {
            this.dialogTitle = this.$t('common.btn.add');
            switch (this.tabFocus) {
                case 0:
                    break;
                case 1:
                    this.showCategoryDialog = true;
                    break;
                case 2:
                    this.showFirstLevelDialog = true;
                    break;
            }
        },
        //取消对话框
        cancel() {
            this.dialogTitle = '';
            switch (this.tabFocus) {
                case 0:
                    break;
                case 1:
                    this.showCategoryDialog = false;
                    break;
                case 2:
                    this.showFirstLevelDialog = false;
                    break;
            }
        },
        resetFormValidate() {
            this.$refs["postForm" + this.tabFocus].clearValidate();
            this.postForm.code = "";
            this.postForm.name = "";
            this.postForm.nameEn = "";
            this.postForm.parentId = null;
            this.postForm.remark = "";
            this.postForm.remarkEn = "";
            this.postForm.status = null;
            this.editId = "";
        },
        //通用编辑
        commonEdit(row) {
            this.editId = row.id;
            this.dialogTitle = this.$t('common.btn.edit');
            getMajorById(row.id).then(res => {
                if (res.code == 200) {
                    this.postForm.code = res.data.code;
                    this.postForm.name = res.data.name;
                    this.postForm.nameEn = res.data.nameEn;
                    this.postForm.status = res.data.status;
                    this.postForm.remark = res.data.remark;
                    this.postForm.parentId = res.data.parentId;
                    switch (this.tabFocus) {
                        case 1:
                            this.showCategoryDialog = true;
                            break;
                        case 2:
                            this.showFirstLevelDialog = true;
                            break;
                    }
                }
            });
        },
        //通用保存
        commonSave() {
            this.$refs["postForm" + this.tabFocus].validate(valid => {
                if (!valid) {
                    return;
                }
                this.postForm.level = this.tabFocus;
                let fn = res => {
                    if (res.code == 200) {
                        this.getDataList();
                        this.cancel();
                    }
                };
                if (this.editId) {
                    let data = _.cloneDeep(this.postForm);
                    data.id = this.editId;
                    editMajor(data).then(fn);
                } else {
                    addMajor(this.postForm).then(fn);
                }
            });
        },
        //通用删除，可删除门类，一级、二级
        commonDelete(row) {
            // this.$confirm(
            //     this.$t("message.deleteConfirm"),
            //     this.$t("message.prompt"),
            //     {
            //         confirmButtonText: this.$t("message.confirm"),
            //         cancelButtonText: this.$t("message.cancel"),
            //         type: "warning"
            //     }
            this.$delConfirm().then(() => {
                deleteMajor({ ids: [row.id] }).then(res => {
                    if (res.code == 200) {
                        this.$message({
                            type: "success",
                            message: this.$t("message.deleteSuccess")
                        });
                        this.getDataList();
                    }
                });
            });
        },
        handleExport() {
            let loading = this.$loading({
                lock: true,
                text: "Loading",
                spinner: "el-icon-loading",
                background: "rgba(255, 255, 255, .48)"
            });
            exportMajor(this.queryForm).then(res => {
                if (res.code == 200) {
                    this.delayRequest(res.data.key, loading);
                } else {
                    loading.close();
                }
            });
        },
        async delayRequest(key, loading) {
            await new Promise(resolve => setTimeout(resolve, 5000));
            getReportStatus(key)
                .then(res => {
                    if (res.code == 200 && res.data.status) {
                        loading.close();
                        let path =
                            "/api/baseresservice/nationalMajor/export?path=" +
                            res.data.path;
                        window.open(path);
                    } else {
                        this.delayRequest(key, loading);
                    }
                })
                .catch(ex => {
                    this.delayRequest(key, loading);
                });
        },
         labelHead(h, { column, $index }) {
            return h("span", { attrs: { title: column.label } }, [
                column.label
            ]);
        },

        test() {
            this.importUrl = "/api/baseresservice/nationalMajor/importMaintenanceSubjects?level=1&type=1"
            this.$refs.uploadDia.open();
        },
        importDegreeRecord(type) {
			if (type == "in") {
                this.uploadTittle = this.$t('professions.importProfessionDegree');
                this.$refs.uploadDialog.open();
                this.importUrl = "/api/baseresservice/nationalMajor/importMaintenanceSubjects?level=1&type=2"
			} else if (type == "out") {
			    window.location.href = downloadDegreeUrl;
			}
        },
        importDomainRecord(type) {
			if (type == "in") {
				 this.uploadTittle = this.$t('professions.importProfessionDemain');
                 this.$refs.uploadDialog.open();
                 this.importUrl = "/api/baseresservice/nationalMajor/importMaintenanceSubjects?level=2&type=2"
			} else if (type == "out") {
			     window.location.href = downloadDomainUrl;
			}
		},
        clearFiles() {
            this.$refs.upload.clearFiles();
            this.fileList = [];
        },
        uploadFile() {
            if (_.isEmpty(this.fileList)) {
                this.$message({
                    type: "info",
                    message: this.$t("message.selectFilePlease")
                });
                return;
            }
            this.$refs.upload.submit();
        },
        uploadDone(res, file, fileList) {
            if (res.code == 200) {
                this.msg='';
                this.$refs.uploadDialog.close();
                this.importCam = null;
                this.importButton = true;
                this.$refs.importRef.open();
                this.delayImportRequest(res.data.key);
            } else {
                this.$message({
                    type: "error",
                    message: this.$t(
                    "culture.profession.uploadFileParsingError"
                    )
                });
                this.clearFiles();
                this.importButton = false;
            }
        },
        async delayImportRequest(key) {
            await new Promise(resolve => setTimeout(resolve, 5000));
                getimportStatus(key).then(res => {
                     this.importCam = res.data;
                    if (res.code == 200 && res.data.status) {
                            if(res.data.success){
                                this.$message({
                                    type: "success",
                                    message: this.$t("common.upload.uploadCompleted")
                                 });
                                 this.importCam = {
                                    doneCount: 1,
                                    updateCount: 1,
                                    total: 2
                                };
                                this.importCam.total = this.importCam.doneCount+ this.importCam.updateCount;
                               this.fontStyle = 'font-size: 15px;color: #606266;';
                               const total = res.data.total;
                               const doneCount = res.data.doneCount ? res.data.doneCount : 0;
                               const updateCount = res.data.updateCount ? res.data.updateCount : 0;
                               this.msg =this.$t("common.upload.total")+total+this.$t("common.upload.num")+"，"+
                               this.$t("common.upload.success")+doneCount+this.$t("common.upload.num")+"，"+
                               this.$t("common.upload.update")+ updateCount+this.$t("common.upload.num")+"，"+
                               this.$t("common.upload.fialed")+(total-doneCount-updateCount)+this.$t("common.upload.num");
                               if((doneCount||updateCount)&&(total-doneCount-updateCount)){
                                    this.errorInfo1 = this.$t("common.upload.errorInfo1");
                                    this.errorInfo2 = this.$t("common.upload.errorInfo2");
                               }else {
                                    this.errorInfo1 = "";
                                    this.errorInfo2 = "";
                               }
                               if(doneCount===0&&updateCount===0){
                                    this.$message({
                                    type: "error",
                                    message: this.$t("common.upload.errorInfo")
                                });
                                  this.errorInfo1 = this.$t("common.upload.errorInfo1");
                                    this.errorInfo2 = this.$t("common.upload.errorInfo2");
                                }
                             }else{
                                  this.importCam = {
                                    doneCount: 1,
                                    updateCount: 1,
                                    total: 2
                                };
                                 this.$refs.importRef.close();
                                this.$message({
                                    type: "error",
                                    message: res.data.msg
                                });
                                // this.fontStyle = 'font-size: 15px;color: red'
                                // this.msg = res.data.msg;
                             }

                    } else {
                        this.delayImportRequest(key, loading);
                    }
                }).catch(ex => {
                        this.delayImportRequest(key, loading)});
        },
        onError(err, file, fileList) {
            let msg = JSON.parse(err.message);
            this.$message({
                    type: "error",
                    message: msg.message
            });
        },
        beforeRemove(file, fileList) {
			return this.$confirm(this.$t("common.upload.remove")+` ${ file.name }？`);
		},
		beforeAvatarUpload(file){
            let extName = file.name
				.substring(file.name.indexOf(".") + 1)
				.toLowerCase()
				.trim();
            if (!(extName === "xls" || extName === "xlsx")) {
				this.$message({
					type: "error",
					message: this.$t("common.upload.unSupportesFileType")
				});
				 this.clearFiles();
				return;
			}
			if(!(file.size/1024/1024 < 3)){
				this.$message({
					type: "error",
					message: this.$t("common.upload.sizeLimit3M")
				});
                this.clearFiles();
                return;
			}
        },
    closeFresh(){
        this.onSubmit();
    },
    }
};
</script>
<style lang="scss" scoped>
.tab {
    margin: 20px 0;
    overflow: auto;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    div {
        float: left;
    }
    .split {
        margin: 0 20px;
    }
    .current {
        color: #262626;
    }
}
</style>
